package love.yuanmeng.guetcoalsystem.service.impl;/*
 *   @Studio:CHJY · 源梦科技
 *   @Author:zjj
 *   @Ide:IntelliJ IDEA
 *   @Creation time:2021/10/16 23:11
 */

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import love.yuanmeng.guetcoalsystem.mapper.MessageMapper;
import love.yuanmeng.guetcoalsystem.pojo.Message;
import love.yuanmeng.guetcoalsystem.service.MessageService;
import love.yuanmeng.guetcoalsystem.util.RandomUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MessaggeServiceImpl implements MessageService {
    @Autowired
    MessageMapper messageMapper;
    @Override
    public boolean inserMessage(Message message) {
        message.setCreateTime(RandomUtils.getTime());
        return messageMapper.insert(message)==1;
    }

    @Override
    public int updataMessage(Message message) {
        UpdateWrapper<Message> messageUpdateWrapper = new UpdateWrapper<>();
        messageUpdateWrapper.eq("id", message.getId());
        return messageMapper.update(message, messageUpdateWrapper);
    }

    @Override
    public List<Message> getMessageByUserid(String userid) {
        List<Message> messageList = messageMapper.selectList(new QueryWrapper<Message>().eq("userid", userid).orderByDesc("create_time"));
        if(messageList!=null && messageList.size()>0) return messageList;
        return null;
    }
}
